﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/**
 * 使用 object 来代替具体类型
 */
namespace BiliBiliCSharpStudy.ch30.d03 {
    class HelloGeneric3 {
        public static void Demo() {
            Test1();
        }
        public static void Test1() {
            Apple apple = new Apple() { Color = "Red" };
            Book book = new Book() { Name = "笑傲江湖" };
            Box box1 = new Box() { Cargo = apple };
            Box box2 = new Box() { Cargo = book };
            Console.WriteLine((box1.Cargo as Apple)?.Color);
            Console.WriteLine((box2.Cargo as Book)?.Name);
        }
    }

    class Apple {
        public string Color { get; set; }
    }

    class Book {
        public string Name { get; set; }
    }
    class Box {
        public object Cargo { get; set; }
    }
}
